package com.chare.Controller;


import com.chare.pojo.Employee;
import com.chare.pojo.RespBean;
import com.chare.pojo.Salary;
import com.chare.service.ISalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shi
 * @since 2022-06-17
 */
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {
    @Autowired
    private ISalaryService salaryService;
    @ApiModelProperty(value = "获得所有工资套账")
    @GetMapping("/")
    public List<Salary> getAll()
    {
        return salaryService.list();
    }
    @ApiModelProperty(value = "删除工资套帐")
    @DeleteMapping("/{id}")
    public RespBean delete(@PathVariable Integer id)

    {
        if(salaryService.removeById(id))
        {
            return  RespBean.success("删除成功");
        }
        return  RespBean.error("删除失败");
    }
    @ApiModelProperty(value = "添加工资套账")
    @PostMapping("/")
    public  RespBean addSalary(@RequestBody Salary salary)
    {
        salary.setCreateDate(LocalDateTime.now());
        if(salaryService.save(salary))
        {
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");

    }
    @ApiModelProperty(value = "修改工资套账")
    @PutMapping("/")
    public  RespBean update(@RequestBody Salary salary)
    {
        if(salaryService.updateById(salary))
        {
            return RespBean.success("修改成功");
        }
        return RespBean.error("修改失败");
    }
}
